package com.wenx.ftpcamel;

import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.model.ModelCamelContext;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * Created by wenx on 2019-07-22 10:07
 */
public class FileTest4 {

    public static void main(String[] args) throws Exception {
        ModelCamelContext camelContext = new DefaultCamelContext();

        camelContext.start();

        camelContext.addRoutes(new RouteBuilder() {

            @Override
            public void configure() {
                LocalDateTime start = LocalDateTime.now();
                System.out.println("开始 "+ start.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
                from("quartz://825da6a0-7a77-49bf-8bbe-0301f0ee6957?cron=0 * * * * ? *&stateful=true")
                        .to("http://localhost:8088/rest/api/getFileInputStream")
                        .process(exchange -> {
                            LocalDateTime get = LocalDateTime.now();
                            System.out.println("读取文件完成 "+ get.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
                            exchange.getOut().setBody(exchange.getIn().getBody());
                            exchange.getOut().setHeader(Exchange.FILE_NAME,"docker.exe");
                            //exchange.getOut().setBody(fis);
                        })
                        .to("file:D:\\test")
                        .process(exchange -> {
                            LocalDateTime get = LocalDateTime.now();
                            System.out.println("写入文件完成 "+ get.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
                        });
            }
        });

        synchronized (FileDemo1.class) {
            FileDemo1.class.wait();
        }
    }

}
